package com.everspring.mapstruct.use.service;

import com.alibaba.fastjson.JSON;
import com.everspring.mapstruct.use.mapping.NewOrderMapping;
import com.everspring.mapstruct.use.mapping.OrderMapping;
import com.everspring.mapstruct.use.model.Order;
import com.everspring.mapstruct.use.model.OrderDetail;
import com.everspring.mapstruct.use.model.OrderVo;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Description： TODO
 * Date： 2020/9/15 15:56
 *
 * @author changchun.xue
 */
@Slf4j
@Service
public class MappingServiceImpl {

    public void mappingVo() {
        OrderDetail detail_1 = OrderDetail.builder().id(111999L).orderId(111L).skuId(9999L).build();
        OrderDetail detail_2 = OrderDetail.builder().id(222999L).orderId(111L).skuId(6666L).build();
        List<OrderDetail> orderDetails = Lists.newArrayList(detail_1, detail_2);
        Order order = Order.builder().id(111L).orderDate(new Date()).price(BigDecimal.valueOf(3.25)).
                productName("空调").status(1001).orderDetailList(orderDetails).build();

        OrderVo orderVo1 = OrderMapping.INSTANCE.toVo(order);
        log.info("self test mappingVo：{}", JSON.toJSONString(orderVo1));

        List<Order> orders = Lists.newArrayList(order);
        OrderVo orderVo = NewOrderMapping.INSTANCE.source2Target(order);
        log.info("test mappingVo：{}", JSON.toJSONString(orderVo));

        List<OrderVo> vos = NewOrderMapping.INSTANCE.sources2Targets(orders);
        log.info("test mappingVo List：{}", JSON.toJSONString(orderVo));
    }

    public void mappingEntity() {

    }

    public void mappingList() {

    }

}
